from collections import namedtuple
from unittest.mock import MagicMock

import pytest

from common import OperatingSystem
from common.types import NetworkPort, NetworkProtocol, PortStatus
from infection_monkey.i_puppet import PortScanData, TargetHostPorts

DomainUser = namedtuple("DomainUser", ["domain", "username"])


@pytest.fixture(scope="module")
def local_user():
    return DomainUser("TEST-DOMAIN", "localuser")


def _create_windows_host(http_enabled, https_enabled):
    no_ssl_port = NetworkPort(5985)
    ssl_port = NetworkPort(5986)

    host = MagicMock()
    host.operating_system = OperatingSystem.WINDOWS
    host.ports_status = TargetHostPorts()

    if http_enabled:
        host.ports_status.tcp_ports[no_ssl_port] = PortScanData(
            port=no_ssl_port, status=PortStatus.OPEN, protocol=NetworkProtocol.TCP
        )

    if https_enabled:
        host.ports_status.tcp_ports[ssl_port] = PortScanData(
            port=ssl_port, status=PortStatus.OPEN, protocol=NetworkProtocol.TCP
        )

    return host


@pytest.fixture
def https_only_host():
    return _create_windows_host(False, True)


@pytest.fixture
def http_only_host():
    return _create_windows_host(True, False)


@pytest.fixture
def http_and_https_both_enabled_host():
    return _create_windows_host(True, True)


@pytest.fixture
def powershell_disabled_host():
    return _create_windows_host(False, False)
